package com.mysoft.gfyx.common.rpc.bigdata.impl;

import com.mysoft.gfyx.common.concurrency.CacheAgentService;
import com.mysoft.gfyx.common.rpc.bigdata.BigDataClientConfiguration;
import com.mysoft.gfyx.common.rpc.bigdata.BigDataClientService;
import com.mysoft.gfyx.common.rpc.bigdata.BigDataClientFactoryService;
import feign.Feign;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class BigDataClientFactoryServiceImpl implements BigDataClientFactoryService {
    @Value("${bigdata.host}")
    private String host;

    @Value("${bigdata.app_id}")
    private String appId;

    @Value("${bigdata.app_key}")
    private String appKey;

    @Value("${bigdata.app_secret}")
    private String appSecret;

    @Autowired
    private CacheAgentService cacheAgentService;


    public BigDataClientService getBigDataClientService() {
        return Feign.builder()
                .encoder(new JacksonEncoder())
                .decoder(new JacksonDecoder())
                .requestInterceptor(new BigDataClientConfiguration(host, appId, appKey, appSecret, cacheAgentService))
                .target(BigDataClientService.class, host);
    }
}
